package org.lightpersist.hibernate;

import net.jcip.annotations.ThreadSafe;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import com.google.inject.Inject;
import com.google.inject.Provider;
/**
 * 
 * @author GL
 *
 */
import com.google.inject.Singleton;
@ThreadSafe
@Singleton
public class SessionFactoryProvider implements Provider<SessionFactory>{

	private SessionFactory sessionFactory;
	private final Configuration configuration;
	
	@Inject
	public SessionFactoryProvider(Configuration configuration) {
		this.configuration = configuration;
	}
	
	public SessionFactory get() {
		if(sessionFactory == null){
			synchronized (this) {
				if(sessionFactory == null){
					sessionFactory = configuration.buildSessionFactory();
				}
			}
		}
		return sessionFactory;
	}

}
